﻿@{
    /*
    *说明：用户管理
     */
}
@{
    ViewBag.Title = "用户管理";
    Layout = "~/Areas/admin/Views/Shared/_Layout.cshtml";
}
@using System.Data;
@using Lk.WebTow.Common;
@using Lk.WebTow.Areas.Admin.Controllers;

<div class="page-content">
    <div class="page-header">
        <div class="toolbar">
            <div class="l-list">
                <ul class="icon-list">
                    <li><a href="manager_edit?act=add&dept_id=@ViewBag.dept_id"><i class="fa fa-pencil-square-o"></i><span>新增</span></a></li>
                    <li><a class="all" href="javascript:;" onclick="checkAll(this);"><i class="fa fa-check-square-o"></i><span>全选</span></a></li>
                    <li><a id="btnDelete" class="del" href="javascript:;"><i class="fa fa-trash"></i><span>删除</span></a></li>
                </ul>
            </div>
            <div class="r-list">
                <div class="menu-list">
                    <div class="col-sm-9">
                        <select id="role_id" name="role_id" class="keyword">
                            <option selected="selected" value="0">请选择角色</option>
                            @foreach (var item in ViewBag.roles)
                            {
                                <option value="@item.Id">@item.RoleName</option>
                            }
                        </select>
                    </div>
                </div>
                <input name="txtKeywords" type="text" id="txtKeywords" class="keyword" placeholder="请输入用户名" />
                <button id="btnSearch" class="btn-search"><i class="fa fa-search"></i>查询</button>
            </div>

        </div>
    </div><!-- /.page-header -->

    <table class="table table-striped table-bordered table-hover ltable">
        <thead>
            <tr>
                <th class="center" width="8%">选择</th>
                <th>用户名</th>
                <th width="12%">姓名</th>
                <th width="12%">电话</th>
                <th width="12%">角色</th>
                <th width="16%">添加时间</th>
                <th width="8%">状态</th>
                <th width="8%">操作</th>
            </tr>
        </thead>
        <tbody id="page_list"></tbody>
    </table>
    <div id="pagination" class="default"></div>
</div>
@section includeJs{
    <script type="text/javascript">
    $(function () {
        //删除
        $("#btnDelete").click(function () {
            var ids = chkVal("chkId");
            $confirm("您确定要删除吗?", function () {
                $.ajaxPostJson("@Url.Action("ManagerDel", "Manager", new { Area = "admin" })", { ids: ids }, function (result) {
                    if (result.status > 0) {
                        $alert(result.message);
                    } else {
                        $alert(result.message);
                    }
                    var url = "managers";
                    self.location = url;
                }, function () {
                    var url = "managers";
                    delAlert("删除失败或权限不够！", url);
                }
                , function (XMLHttpRequest) {//beforeSend
                    $("#btnDelete").attr("disabled", true);
                });

            })
        });

    });
    </script>
    <script src="~/ad_min/js/jq/jquery.pagination.js"></script>
    <script type="text/javascript">
        $(function(){
            //搜索事件
            $("#btnSearch").click(function(){
                var role_id=$("#role_id").val();
                var keyword=$(".keyword").val();
                AjaxPageList('#page_list', '#pagination', 10, '@ViewBag.TotalCount', '@Url.Action("ManagerList", "Manager", new { Area = "admin" })?deptid=@ViewBag.DeptId&rid='+role_id+'&keyword='+keyword+'');
            });
            //初始化列表
            AjaxPageList('#page_list', '#pagination', 10, '@ViewBag.TotalCount', '@Url.Action("ManagerList", "Manager", new { Area = "admin" })?rid=@ViewBag.RId&deptid=@ViewBag.DeptId');
        });
        /*显示AJAX分页列表*/
        function AjaxPageList(listDiv, pageDiv, pageSize, pageCount, sendUrl) {
            //pageIndex -页面索引初始值
            //pageSize -每页显示条数初始化
            //pageCount -取得总页数
            InitPage(0);//初始化数据
            $(pageDiv).pagination(pageCount, {
                callback: pageselectCallback,
                prev_text: "« 上一页",
                next_text: "下一页 »",
                items_per_page: pageSize,
                num_display_entries: 3,
                current_page: 0,
                num_edge_entries: 5,
                link_to: "javascript:;"
            });

            //分页点击事件
            function pageselectCallback(page_id, jq) {
                InitPage(page_id);
            }
            //请求数据
            function InitPage(page_id) {
                page_id++;
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    url: sendUrl + "&pageSize=" + pageSize + "&pageIndex=" + page_id,
                    beforeSend: function (XMLHttpRequest) {
                        $(listDiv).html('<p style="line-height:35px;">正在很努力加载，请稍候...</p>');
                    },
                    success: function (data) {
                        console.log(data);
                        var strHtml = '';
                        var row=data;
                        for (var i in row) {
                            strHtml += '<tr>'
                            +'<td class="center"><label class="checkall"><input name="chkId" type="checkbox" class="ace" value="'+row[i].Id+'" /><span class="lbl"></span></label></td>'
                            +'<td><a href="manager_edit?act=Edit&id='+row[i].Id+'&deptId='+((row[i].DeptId+"")!="undefined"?row[i].DeptId:"0")+'">' + row[i].UserName + '</a></td>'
                            +'<td>' + row[i].RealName + '</td>'
                            +'<td>' + row[i].Telephone + '</td>'
                            +'<td>' + row[i].RoleName + '</td>'
                            +'<td>' + row[i].AddTime + '</td>'
                            +'<td>' + (row[i].IsLock=="0" ? "正常" : "禁用") + '</td>'
                            +'<td align="center"><a href="manager_edit?act=Edit&id='+row[i].Id+'&deptId='+((row[i].DeptId+"")!="undefined"?row[i].DeptId:"0")+'">修改</a></td>'
                            + '</tr>';
                        }
                        //alert(strHtml);
                        $(listDiv).html(strHtml);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $(listDiv).html('<p style="line-height:35px;">暂无数据！</p>');
                    }
                });
            }
        }
    </script>
}